/*

This file sets up tables

*/

use "/projects/data/dataSTATA/combined/combined_iv_energy.dta", clear

* drop obs that would be excluded from regressions --> generate constant sample
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

reghdfe lelec_price_init instr_B_cl instr_B_ng instr_B_pa instr_B_cl_init instr_B_ng_init instr_B_pa_init   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

gen age = year - firstyear

*>--------- define rounding function for regs---------------------<
* copied from rounding_regs.do Census file provided

capture program drop round
program define round, eclass
   mat A = e(b)
   forval j = 1/`=colsof(matrix(A))' { 
      mat A[1,`j'] = round(A[1,`j'],10^(floor(log10(abs(A[1,`j'])))-3))
   } 
   ereturn repost b = A

   if e(N)>=15&e(N)<=99 ereturn scalar N = round(e(N), 10)
   if e(N)>=100&e(N)<=999 ereturn scalar N = round(e(N), 50)
   if e(N)>=1000&e(N)<=9999 ereturn scalar N = round(e(N), 100)
   if e(N)>=10000&e(N)<=99999 ereturn scalar N = round(e(N), 500)
   if e(N)>=100000&e(N)<=999999 ereturn scalar N = round(e(N), 1000)
   if e(N)>=1000000 ereturn scalar N = round(e(N),10^(floor(log10(e(N)))-3))

   if e(N)<15 {
   scalar N_less15=1
   ereturn scalar N=.
   }

   if e(df_r)>=15&e(df_r)<=99 ereturn scalar df_r = round(e(df_r), 10)
   if e(df_r)>=100&e(df_r)<=999 ereturn scalar df_r = round(e(df_r), 50)
   if e(df_r)>=1000&e(df_r)<=9999 ereturn scalar df_r = round(e(df_r), 100)
   if e(df_r)>=10000&e(df_r)<=99999 ereturn scalar df_r = round(e(df_r), 500)
   if e(df_r)>=100000&e(df_r)<=999999 ereturn scalar df_r = round(e(df_r), 1000)
   if e(df_r)>=1000000 ereturn scalar df_r = round(e(df_r),10^(floor(log10(e(df_r)))-3))

   if e(df_r)<15 {
   scalar df_less15=1
   ereturn scalar df_r=.
   }


   capture ereturn scalar r2 = round(e(r2),10^(floor(log10(e(r2)))-3))
   capture ereturn scalar r2_a = round(e(r2_a),10^(floor(log10(e(r2_a)))-3))
   capture ereturn scalar F = round(e(F),10^(floor(log10(e(F)))-3))
   capture ereturn scalar rmse = round(e(rmse),10^(floor(log10(e(rmse)))-3))
   capture ereturn scalar mss = round(e(mss),10^(floor(log10(e(mss)))-3))
   capture ereturn scalar rss = round(e(rss),10^(floor(log10(e(rss)))-3))
   capture ereturn scalar rkf = round(e(rkf),10^(floor(log10(e(rkf)))-3))

end


*>------------------------------ Table A.1 ---------------------<

* full sample and electricity intensive industries -- energy outcomes
preserve
mat M = J(11, 2,.)

* round numerators and denominators for variables where that are ratios
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 firstyear year ee pe elec_price_init tvs co2_int_i_both btu_int_i_both
gen  elec_price_round = ee / pe 
gen  elec_int_round = pe / tvs

* Sum Stats Col 1 -- All Industries
sum year
gen mean_year = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_year
sum mean_year 
mat M[1,1] = `r(mean)'

sum firstyear
gen mean_firstyear = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_firstyear
sum mean_firstyear 
mat M[2,1] = `r(mean)'

sum age
gen mean_age = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_age
sum mean_age
mat M[3,1] = `r(mean)'

sum elec_price_round
gen mean_elecprice = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elecprice
sum mean_elecprice 
mat M[4,1] = `r(mean)'

sum elec_price_init
gen mean_elecprice_init = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elecprice_init
sum mean_elecprice_init 
mat M[5,1] = `r(mean)'

sum elec_int_round
gen mean_elec_int = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elec_int
sum mean_elec_int
mat M[6,1] = `r(mean)'

sum co2_int_i_both 
gen mean_co2_iboth = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_co2_iboth
sum mean_co2_iboth
mat M[7,1] = `r(mean)'

sum btu_int_i_both
gen mean_btu_iboth = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_btu_iboth
sum mean_btu_iboth
mat M[8,1] = `r(mean)'

sum ee
gen mean_ee = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_ee
sum mean_ee
mat M[9,1] = `r(mean)'

sum pe
gen mean_pe = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_pe
sum mean_pe
mat M[10,1] = `r(mean)'

sum firstyear
gen N = `r(N)'
do /projects/programs/codeSTATA/B_analysis/rounding_N.do N
sum N
mat M[11,1] = `r(mean)'

* Sum stats Col 2 -- electricity-intensive industries
keep if elec_perc_ind > 0.7
sum year
gen mean_year2 = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_year2
sum mean_year2 
mat M[1,2] = `r(mean)'

sum firstyear
gen mean_firstyear2 = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_firstyear2
sum mean_firstyear2 
mat M[2,2] = `r(mean)'

sum age
gen mean_age2 = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_age2
sum mean_age2
mat M[3,2] = `r(mean)'

sum elec_price_round
gen mean_elecprice2 = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elecprice2
sum mean_elecprice2 
mat M[4,2] = `r(mean)'

sum elec_price_init
gen mean_elecprice_init2 = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elecprice_init2
sum mean_elecprice_init2 
mat M[5,2] = `r(mean)'

sum elec_int_round
gen mean_elec_int2 = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_elec_int2
sum mean_elec_int2
mat M[6,2] = `r(mean)'

sum co2_int_i_both 
gen mean_co2_iboth2 = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_co2_iboth2
sum mean_co2_iboth2
mat M[7,2] = `r(mean)'

sum btu_int_i_both 
gen mean_btu_iboth2 = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_btu_iboth2
sum mean_btu_iboth2
mat M[8,2] = `r(mean)'

sum ee
gen mean_ee2 = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_ee2
sum mean_ee2
mat M[9,2] = `r(mean)'

sum pe
gen mean_pe2 = `r(mean)'
do /projects/programs/codeSTATA/B_analysis/rounding_4sigdig_v2 mean_pe2
sum mean_pe2
mat M[10,2] = `r(mean)'

sum firstyear
gen N2 = `r(N)'
do /projects/programs/codeSTATA/B_analysis/rounding_N.do N2
sum N2
mat M[11,2] = `r(mean)'


set linesize 255
svmat M
format M* %25.2f
keep M*
matrix colnames M = All_Industries Electricity_Intensive_Industries
matrix rownames M = Year Entry_Year Age Current_Electricity_Price Initial_Electricity_Price Electricity_Intensity CO2_Intensity BTU_Intensity Cost_of_Purchased_Electricity Quantity_of_Electricity N
esttab matrix(M) using "/projects/results/tables/summary_stats.xls", replace
	
restore



*>------------------------------ Table 1 ----------------------------<
reghdfe lelec_price_init instr_B_cl instr_B_ng instr_B_pa instr_B_cl_init instr_B_ng_init instr_B_pa_init   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
reghdfe lelec_price instr_B_cl instr_B_ng instr_B_pa instr_B_cl_init instr_B_ng_init instr_B_pa_init   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

esttab using "/projects/results/tables/firststage.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(instr_B_cl instr_B_ng instr_B_pa instr_B_cl_init instr_B_ng_init instr_B_pa_init) mtitles("Initial Elec. Prices" "Current Elec. Prices") coeflabels(instr_B_cl Coal_ShareXCurrent_Coal_Price instr_B_ng Natural_Gas_ShareXCurrent_Natural_Gas_Price instr_B_pa Petroleum_ShareXCurrent_Petroleum_Price instr_B_cl_init Coal_ShareXInitial_Coal_Price instr_B_ng_init Natural_Gas_ShareXInitial_Natural_Gas_Price instr_B_pa_init Petroleum_ShareXInitial_Petroleum_Price)
eststo clear 

*>------------------------------ Table 2 ---------------------------------<
* electricity 
reghdfe lelec_int  instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init  [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

* electricity intensive industries
reghdfe lelec_int  instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init  [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

* co2 
reghdfe lco2_int_i_both  instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init  [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

* btu
reghdfe lbtu_int_i_both  instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init  [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

esttab using "/projects/results/tables/reducedform.xls", b(3) se(3) obslast nonumbers replace star(* 0.10 ** 0.05 *** 0.01) keep(instr_B_cl instr_B_ng instr_B_pa instr_B_cl_init instr_B_ng_init instr_B_pa_init) mgroups("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity" , pattern(1 1 1 1 )) mtitles("(1)" "(2)" "(3)" "(4)") coeflabels(instr_B_cl Coal_ShareXCurrent_Coal_Price instr_B_ng Natural_Gas_ShareXCurrent_Natural_Gas_Price instr_B_pa Petroleum_ShareXCurrent_Petroleum_Price instr_B_cl_init Coal_ShareXInitial_Coal_Price instr_B_ng_init Natural_Gas_ShareXInitial_Natural_Gas_Price instr_B_pa_init Petroleum_ShareXInitial_Petroleum_Price)
eststo clear 

*>----------------- Table 3 ------------------------------------------------<

* OLS
reghdfe lelec_int  lelec_price lelec_price_init  [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
reghdfe lelec_int  lelec_price lelec_price_init  [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
reghdfe lco2_int_i_both  lelec_price lelec_price_init  [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
reghdfe lbtu_int_i_both  lelec_price lelec_price_init  [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

* IV
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

esttab using "/projects/results/tables/ols_iv.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity" "Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear 



*>------------------------ Table A.7 -----------------------------------------<

* year x industry, first year x industry, state x industry FE
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.bestnaics i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.bestnaics i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.bestnaics i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.bestnaics i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

esttab using "/projects/results/tables/robustness.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity") title(" year x industry, first year x industry, state x industry FE") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear

* unweighted
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) , absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) , absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) , absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) , absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round 

esttab using "/projects/results/tables/robustness.xls", b(3) se(3) obslast append star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity") title("Unweighted") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear

* state x year trends
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics c.year##i.fipsst) cluster(fipsst)
eststo: round
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics c.year##i.fipsst) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round
ivreghdfe lco2_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics c.year##i.fipsst) cluster(fipsst)
eststo: round
ivreghdfe lbtu_int_i_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics c.year##i.fipsst) cluster(fipsst)
eststo: round

esttab using "/projects/results/tables/robustness.xls", b(3) se(3) obslast append star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity") title("state x year trends") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear

* co2, btu excluding imputed values
preserve
ivreghdfe lco2_int_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics ) cluster(fipsst)
keep if e(sample)

ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

ivreghdfe lco2_int_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics ) cluster(fipsst)
eststo: round
ivreghdfe lbtu_int_both  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics ) cluster(fipsst)
eststo: round

esttab using "/projects/results/tables/robustness.xls", b(3) se(3) obslast append star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity") title("co2, btu excluding imputed values") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear
restore

* without ASM Fuels Trailers
preserve
ivreghdfe lco2_int_i  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample) 

ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

ivreghdfe lco2_int_i  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lbtu_int_i  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
esttab using "/projects/results/tables/robustness.xls", b(3) se(3) obslast append star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity") title("co2, btu excluding ASM Fuels Trailers") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear
restore

* without ASM Fuels Trailers or Imputed Values
preserve
ivreghdfe lco2_int (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
keep if e(sample)

ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lelec_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init)   [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

ivreghdfe lco2_int (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
ivreghdfe lbtu_int  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round
esttab using "/projects/results/tables/robustness.xls", b(3) se(3) obslast append star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init) mtitles("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity") title("co2, btu excluding ASM Fuels Trailers and imputed values") coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear
restore

*>------------------- Table A.6 ------------------------------------------<
* labor hours
ivreghdfe lcl  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

* materials
ivreghdfe lcm  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

* capital investment
drop lck 
gen lck = log(1+ck)
ivreghdfe lck  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

* total quantity of energy purchased
gen lpe = log(pe)
ivreghdfe lpe  (lelec_price lelec_price_init = instr_B_cl instr_B_ng instr_B_pa  instr_B_cl_init instr_B_ng_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

esttab using "/projects/results/tables/otheroutcomes.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init ) mtitles("Labor Hours" "Materials Costs" "Capital Investment" "Total Purchased Electricity" ) coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price)) scalars("rkf K-P F stat") sfmt(1)
eststo clear 

*>--------------------------- Table 6 --------------------------<

* age
ivreghdfe lelec_int  (lelec_price c.age#c.lelec_price_init lelec_price_init= instr_B_cl instr_B_ng instr_B_pa  c.age#c.instr_B_cl_init instr_B_cl_init c.age#c.instr_B_ng_init  instr_B_ng_init c.age#c.instr_B_pa_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

ivreghdfe lelec_int  (lelec_price c.age#c.lelec_price_init lelec_price_init= instr_B_cl instr_B_ng instr_B_pa  c.age#c.instr_B_cl_init instr_B_cl_init c.age#c.instr_B_ng_init  instr_B_ng_init c.age#c.instr_B_pa_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst), if elec_perc_ind > 0.7
eststo: round

ivreghdfe lco2_int_i_both  (lelec_price c.age#c.lelec_price_init lelec_price_init= instr_B_cl instr_B_ng instr_B_pa  c.age#c.instr_B_cl_init instr_B_cl_init c.age#c.instr_B_ng_init  instr_B_ng_init c.age#c.instr_B_pa_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

ivreghdfe lbtu_int_i_both  (lelec_price c.age#c.lelec_price_init lelec_price_init= instr_B_cl instr_B_ng instr_B_pa  c.age#c.instr_B_cl_init instr_B_cl_init c.age#c.instr_B_ng_init  instr_B_ng_init c.age#c.instr_B_pa_init instr_B_pa_init) [pw=wt_cmf], absorb(i.y##i.firstyear##i.bestnaics i.fipsst##i.bestnaics) cluster(fipsst)
eststo: round

esttab using "/projects/results/tables/heterogeneity_age.xls", b(3) se(3) obslast replace star(* 0.10 ** 0.05 *** 0.01) keep(lelec_price lelec_price_init c.age#c.lelec_price_init) mtitles("Electricity Intensity" "Electricity Intensity, Elec. Intensive Industries" "CO2 Intensity" "BTU Intensity" ) coeflabels(lelec_price log(Current_Electricity_Price) lelec_price_init log(Initial_Electricity_Price) c.age#c.lelec_price_init log(Initial_Electricity_Price)XAge) scalars("rkf K-P F stat") sfmt(1)
eststo clear 

